package br.com.bean;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;
import org.primefaces.event.SelectEvent;

import br.com.domain.Luis;
import br.com.domain.Domain;
import br.com.exception.BeanException;
import br.com.exception.ServiceException;
import br.com.filter.LuisFilter;
import br.com.service.LuisService;
import br.com.service.GenericServiceImpl;
import br.com.util.DomainListDataModel;

@ViewAccessScoped
@Named
public class LuisBean extends GenericBean{
	
	private static final long serialVersionUID = 1L;
	
	/**************************************************************************/
	/**                                ATRIBUTOS                             **/
	/**************************************************************************/
	
	@Inject /** Service **/	 
	private LuisService luisService; 
	
	/** Objeto Principal do Bean **/
	private Luis luis = new Luis();	
	
	/** Lista Principal do Bean **/
	private DomainListDataModel listLuis;
	
	/** Lista Principal do Bean **/
	private List<Luis> listLuisSelecionados;
	
	/** Objeto de Filtro do Bean **/
	private LuisFilter luisFilter = new LuisFilter();	  
	
	/**************************************************************************/
	/**                                M�TODOS                               **/
	/**************************************************************************/
	
	/**
	 * ON LOAD PAGE 
	 * @return void
	 */
	public void loadPage() {
	}
	
	/**
	 * NOVO REGISTRO
	 * @return void
	 */
	public void novo()  {
		this.activeModoNovo();
		this.luis = new Luis();
		this.goPage("pageLuisCad");
	}
	
	/**
	 * SALVAR REGISTRO
	 * @return void
	 */
	public void salvar()  {	
        try {
			this.salvar(this.luis);
			this.goPage("pageLuisList");
		} catch (BeanException e) {
			MessageBean.showAlertMessage(e.getMessage());
		}
	}
	
	/**
	 * EDITAR REGISTRO
	 * @return void
	 */
	public void editar() {
		try {
			this.editar(this.luis);
			this.goPage("pageLuisCad");
		} catch (BeanException e) {
			MessageBean.showAlertMessage(e.getMessage());
		}
	}
	
	/**
	 * EXCLUIR REGISTROS SELECIONADOS
	 * @return void
	 */
	public void excluir()  {
		try {
			this.excluir(this.listLuisSelecionados);
		} catch (ServiceException e) {
			MessageBean.showErrorMessage(e.getMessage() );
		}
	}
	
	/**
	 * VISUALIZAR REGISTRO
	 * @return void
	 */
	public void visualizar()  {
		super.activeModoVisualizar();
		this.goPage("pageLuisCad");
	}
	
	/**
	 * BUSCAR TODOS OS REGISTROS
	 * @return DomainListDataModel
	 */
	public DomainListDataModel buscarTodos()  {
		try {
			 this.listLuis = this.buscarTodos(Luis.class);
		} catch (BeanException e) {
			MessageBean.showErrorMessage(e.getMessage());
		}
		return this.listLuis;
	}
	
	/**
	 * BUSCAR DADOS POR FILTRO
	 * @return void
	 */
	public void buscarPorFiltro()  {
		try {
			this.listLuis = buscarPorFiltro(this.luisFilter);
		} catch (BeanException e) {
			MessageBean.showErrorMessage(e.getMessage());
		}
	}
	
	/**
	 * SAIR
	 * @return void
	 */
	public void sair() {
	   this.goPage("pageLuisList");
	}
	
	/**
	 * LINHA SELECIONADA
	 * @return void
	 */
	public void onRowSelect(SelectEvent  event) {
		this.luis = (Luis) event.getObject();
				
	}
	
	/**************************************************************************/
	/**                      M�TODOS  COMPLEMENTEARES                        **/
	/**************************************************************************/
	
	 @PostConstruct	 
	 public void initBean() throws ServiceException{
	    this.buscarTodos();
	 }
		
	/**************************************************************************/
	/**                           GET's E SET's                              **/
	/**************************************************************************/
	 @Override
	 public void setGenericService(GenericServiceImpl genericService) {
		super.setGenericService(this.luisService);
	 }
	 
	 @Override
	 public GenericServiceImpl getGenericService() {
		return this.luisService;
	 }
	 
	 @Override
	 public DomainListDataModel getListDomain() {
		 return this.getListLuis();
	 }

	 @Override
	 public List<? extends Domain> getListDomainSelecionados() {
		return this.listLuisSelecionados;
	 }
	 
	 @Override
	 public void setListDomainSelecionados(
			 List<? extends Domain> listDomainSelecionados) {
		 this.listLuisSelecionados = null;
	 }

	 @Override
	 public Boolean getIsButtonDeleteDisabled() {		
		 return this.desabilitarExclusao(this.listLuis, this.listLuisSelecionados);
	 }

	@Override
	public Domain getDomain() {
		return this.luis;
	}
	 
	 public Luis getLuis() {
		 return luis;
	 }

	 public void setLuis(Luis luis) {
		 this.luis = luis;
	 }

	 public LuisFilter getLuisFilter() {
		 return luisFilter;
	 }

	 public void setLuisFilter(LuisFilter luisFilter) {
		 this.luisFilter = luisFilter;
	 }

	 public DomainListDataModel getListLuis() {
		 return listLuis;
	 }

	 public void setListLuis(DomainListDataModel listLuis) {
		 this.listLuis = listLuis;
	 }

	 public List<Luis> getListLuisSelecionados() {
		 return listLuisSelecionados;
	 }

	 public void setListLuisSelecionados(List<Luis> listLuisSelecionados) {
		 this.listLuisSelecionados = listLuisSelecionados;
	 }

	public LuisService getLuisService() {
		return luisService;
	}

	public void setLuisService(LuisService luisService) {
		this.luisService = luisService;
	}

}
